#define  _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

typedef int  BTDatatype;

typedef struct BinaryTreeNode
{
	struct BinaryTreeNode* left;
	struct BinaryTreeNode* right;
	BTDatatype data;
}BTNode;

BTNode* BuyNode(BTDatatype x)
{
	BTNode *newnode = (BTNode *)malloc(sizeof(BTNode));
	assert(newnode);

	newnode->data = x;
	newnode->left = NULL;
	newnode->right = NULL;

	return newnode;
}

BTNode* CreatBinaryTree()
{
	BTNode* node1 = BuyNode(1);
	BTNode* node2 = BuyNode(2);
	BTNode* node3 = BuyNode(3);
	BTNode* node4 = BuyNode(4);
	BTNode* node5 = BuyNode(5);
	BTNode* node6 = BuyNode(6);

	node1->left = node2;
	node1->right = node3;
	node2->left = node4;
	node2->right = node5;
	node3->left = node6;

	return node1;
}

int count = 0;
void TreeSize1(BTNode* root)
{
	if (root == NULL)
	{
		return; 
	}
	count++;

	TreeSize1(root->left);
	TreeSize1(root->right);

}

int TreeSize2(BTNode* root)
{
	return root == NULL ? 0 : \
		TreeSize2(root->left) + TreeSize2(root->right)+1;
}

int TreeKLevel(BTNode* root, int k)
{
	assert(root);

	if (root == NULL)
		return 0;
	if (k == 1)
		return 1;
	return TreeKLevel(root->left, k - 1)+ \
		TreeKLevel(root->right, k - 1);
}



int main()
{
	BTNode* root = CreatBinaryTree();

	count = 0;
	TreeSize1(root);
	printf("%d\n", count);
	count = 0;

	printf("%d\n", TreeSize2(root));

	printf("%d\n", TreeKLevel(root, 2));



	return 0;
}